﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Slja.Model;

namespace Slja.BLL
{
   public enum DescrType
    {
       /// <summary>
       /// 空
       /// </summary>
       None=0,
        /// <summary>
        /// 联系人
        /// </summary>
        LinkMan,
        /// <summary>
        /// 商场
        /// </summary>
        Shop,
        /// <summary>
        /// 客户
        /// </summary>
        Client,
        /// <summary>
        /// 供应商
        /// </summary>
        Supplier      

    }
   public class DescriptioBLL
   {
       /// <summary>
       /// 输出描述信息的工程方法
       /// </summary>
       /// <param name="descrtype">描述的类型</param>
       /// <param name="objid">所描述对象的ID</param>
       /// <returns></returns>
       public static string OutputDescrFactory(string descrtype,string objid)
       {
           DescrType type = (DescrType)Enum.Parse(typeof(DescrType), descrtype, true);
            int lnkID;
            if (int.TryParse(objid, out lnkID) && lnkID > 0)
            {
                return OutputDescrFactory(type, lnkID);
            }           
           return "";
       }
       /// <summary>
       /// 输出描述信息的工厂方法
       /// </summary>
       /// <param name="descrtype">描述的类型</param>
       /// <param name="objid">所描述对象的ID</param>
       /// <returns></returns>
       public static string OutputDescrFactory(DescrType descrtype, int objid)
       {
           string strHtml = "";
           if (descrtype != DescrType.None && objid > 0)
           {
               if (descrtype == DescrType.LinkMan)
               {
                    LinkManBLL bll = new LinkManBLL();                  
                    LinkManModel mdl = bll.GetModel(objid);
                    strHtml = DescriptioBLL.Output_LinkMan(mdl);
                  
               }
           }
           return strHtml;
       }
       /// <summary>
       /// 输出：联系人描述信息
       /// </summary>
       /// <param name="LinkMan"></param>
       /// <returns></returns>
       public static string Output_LinkMan(LinkManModel LinkMan)
       {
           if (LinkMan == null) return "";
           StringBuilder sb = new StringBuilder(32);
           sb.Append("<div class='descr_div'>");
           sb.Append(AddAttrib("电话", LinkMan.JobTel));
           sb.Append(AddAttrib("手机", LinkMan.MobileTel));
           sb.Append("</div>");
           return sb.ToString();
       }
       private static string AddAttrib(string lb, string val)
       {
           if (!string.IsNullOrEmpty(val))
           {
               return string.Format("<span class='descr_lb'>{0}:</span><span class='descr_val'>{1}</span>&nbsp;&nbsp;", lb, val);
           }
           else
           {
               return "";
           }
       } 
   }
}
